#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Volatility/SmileSection.h>
#pragma unmanaged 
#include <ql\termstructures\volatility\sabrinterpolatedsmilesection.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Math::Optimization;
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Volatility {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ISabrInterpolatedSmileSection
	public ref class CSabrInterpolatedSmileSection : 
            public CSmileSection,
            public Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection
	{
	protected: 
		boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>* _ppSabrInterpolatedSmileSection;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection>* _phSabrInterpolatedSmileSection;
#endif
		Object^ _SabrInterpolatedSmileSectionOwner;     // reference to object that manages the storage for this object
	internal:
		CSabrInterpolatedSmileSection (DateTime optionDate, Double forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Double atmVolatility, Cephei::IVector<Double>^ vols, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
		CSabrInterpolatedSmileSection (DateTime optionDate, Cephei::QL::IQuote^ forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Cephei::QL::IQuote^ atmVolatility, Cephei::IVector<Cephei::QL::IQuote^>^ volHandles, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
        CSabrInterpolatedSmileSection (boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>& childNative, Object^ owner);
        CSabrInterpolatedSmileSection (QuantLib::SabrInterpolatedSmileSection& childNative, Object^ owner);
        CSabrInterpolatedSmileSection (CSabrInterpolatedSmileSection^ copy);
        CSabrInterpolatedSmileSection (System::Type^ t);
#ifdef STRUCT
        CSabrInterpolatedSmileSection (QuantLib::SabrInterpolatedSmileSection childNative);
#endif       
#ifdef HANDLE
		CSabrInterpolatedSmileSection (QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection>& childNative, Object^ owner);
		CSabrInterpolatedSmileSection (QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection> childNative);
#endif
		virtual ~CSabrInterpolatedSmileSection ();
		!CSabrInterpolatedSmileSection ();

	internal:
		QuantLib::SabrInterpolatedSmileSection& GetReference ();
		boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>& GetShared ();
		QuantLib::SabrInterpolatedSmileSection* GetPointer ();
        void SetSabrInterpolatedSmileSection (boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> native)
        {
            if (_ppSabrInterpolatedSmileSection != NULL)
                delete _ppSabrInterpolatedSmileSection;
            _ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (native);
            SetSmileSection (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Double Alpha 
        {
		    virtual Double get () ;
        }
        property Double AtmLevel 
        {
		    virtual Double get () ;
        }
        property Double Beta 
        {
		    virtual Double get () ;
        }
        property QL::Math::Optimization::EndCriteria::TypeEnum EndCriteria 
        {
		    virtual QL::Math::Optimization::EndCriteria::TypeEnum get () ;
        }
        property Double MaxError 
        {
		    virtual Double get () ;
        }
        property Double MaxStrike 
        {
		    virtual Double get () ;
        }
        property Double MinStrike 
        {
		    virtual Double get () ;
        }
        property Double Nu 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ PerformCalculations 
        {
		    virtual Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ get () ;
        }
        property Double Rho 
        {
		    virtual Double get () ;
        }
        property Double RmsError 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ Update 
        {
		    virtual Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ get () ;
        }
		virtual Double VarianceImpl (Double strike) ;
		virtual Double VolatilityImpl (Double strike) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CSabrInterpolatedSmileSection_Factory : public System::MarshalByRefObject,  public ISabrInterpolatedSmileSection_Factory
	{
	public:
        virtual ISabrInterpolatedSmileSection^ Create (DateTime optionDate, Double forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Double atmVolatility, Cephei::IVector<Double>^ vols, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
        virtual ISabrInterpolatedSmileSection^ Create (DateTime optionDate, Cephei::QL::IQuote^ forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Cephei::QL::IQuote^ atmVolatility, Cephei::IVector<Cephei::QL::IQuote^>^ volHandles, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Volatility */}
